<template>
    <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :close-on-click-modal="false"
        v-dialogDrag>
        <div class="app-container">
            <el-row :gutter="10" class="mb8">
                <el-col :span="1.5">
                    <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                        v-hasPermi="['develop:LnShebeiWeibao:add']">新增</el-button>
                </el-col>
                <el-col :span="1.5">
                    <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
                        v-hasPermi="['develop:LnShebeiWeibao:export']">导出</el-button>
                </el-col>
                <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
            </el-row>

            <el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" ref="table"
                :max-height="tableMaxHeight">
                <el-table-column type="selection" width="55" align="center" />
                <el-table-column label="所属部门" align="center" prop="haveHouse" />
                <el-table-column label="维保类型" align="center" prop="type" >
                    <template slot-scope="scope">
                        <dict-tag :options="dict.type.weibao_type" :value="scope.row.type" />
                    </template>
                </el-table-column>
                <el-table-column label="审核状态" align="center" prop="shenhestatus" />
                <el-table-column label="使用部门" align="center" prop="haveHouse" />
                <el-table-column label="故障问题" align="center" prop="problem" />
                <el-table-column label="故障类别" align="center" prop="problemType" sortable>
                    <template slot-scope="scope">
                        <dict-tag :options="dict.type.problem_type" :value="scope.row.problemType" />
                    </template>
                </el-table-column>
                <el-table-column label="维保内容" align="center" prop="maintenance" />
                <el-table-column label="维保金额" align="center" prop="money" />
                <el-table-column label="维保时间" align="center" prop="date" width="180">
                    <template slot-scope="scope">
                        <span>{{ parseTime(scope.row.date, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="维保记录" align="center" prop="record" />
                <el-table-column label="维保人" align="center" prop="userName" />
                <el-table-column label="验收记录" align="center" prop="checkContent" />
                <el-table-column label="验收人" align="center" prop="checkName" />
                <el-table-column label="检修申请人" align="center" prop="jianxiuApply" />
                <el-table-column label="检修记录" align="center" prop="jianxiuRecord" />
                <el-table-column label="检修人" align="center" prop="jianxiuName" />
                <el-table-column label="检修时间" align="center" prop="jianxiuDate" width="180">
                    <template slot-scope="scope">
                        <span>{{ parseTime(scope.row.jianxiuDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="更换配件" align="center" prop="peijian" />
                <el-table-column label="配件费" align="center" prop="peijianMoney" />
                <el-table-column label="合计金额" align="center" prop="allMoeny" />
                <el-table-column label="车间主任" align="center" prop="director" />
                <el-table-column label="主管领导" align="center" prop="leader" />
                  <el-table-column label="其他文件" align="center" prop="otherFile"/>
                    <el-table-column label="维修/保养文件" align="center" prop="file"/>
                <el-table-column label="备注" align="center" prop="remark" />
                <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                    <template slot-scope="scope">
                        <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                            v-hasPermi="['develop:LnShebeiWeibao:edit']">修改</el-button>
                        <el-popconfirm :title="`确认删除当前数据项？`" @confirm="handleDelete(scope.row)"
                            style="margin-left: 10px;">
                            <el-button slot="reference" size="mini" type="text" icon="el-icon-delete"
                                v-hasPermi="['develop:LnShebeiWeibao:remove']">删除</el-button>
                        </el-popconfirm>
                    </template>
                </el-table-column>
            </el-table>

            <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList" />
            <maintenance-form ref="maintenanceForm" @ok="getList"></maintenance-form>
        </div>
    </el-dialog>
</template>

<script>
import { deleteAction, getAction } from '@/api/manage'
import maintenanceForm from '@/views/develop/lnShebei/module/maintenanceForm'
export default {
    name: "maintenanceList",
    dicts: ['problem_type','weibao_type'],
    components: { maintenanceForm },
    data() {
        return {
            info:{},
            type:"",
            open: false,
            title: '',
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 设备维修保养表格数据
            dataList: [],
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                status: null,
                name: null,
                code: null,
                pinpai: null,
                xinghao: null,
                haveHouse: null,
                otherFile: null,
                file: null,
                type: null,
                shebeiType: null,
                shenheName: null,
                shenhestatus: null,
                useDept: null,
                problem: null,
                problemType: null,
                maintenance: null,
                money: null,
                date: null,
                record: null,
                userName: null,
                checkContent: null,
                checkName: null,
                jianxiuApply: null,
                jianxiuRecord: null,
                jianxiuName: null,
                jianxiuDate: null,
                peijian: null,
                peijianMoney: null,
                allMoeny: null,
                director: null,
                leader: null
            },
            url: {
                list: '/lnShebeiWeibao/lnShebeiWeibao/list',
                remove: '/lnShebeiWeibao/lnShebeiWeibao/',
                export: '/lnShebeiWeibao/lnShebeiWeibao/export',
            },
            tableMaxHeight: window.innerHeight - 320,
        };
    },

    created() {
        this.getList();
        window.addEventListener('resize', this.getTableHeight);
    },
    destroyed() {
        window.removeEventListener('resize', this.getTableHeight)
    },
    methods: {
        handleAdds(row) {
            this.info = row
            this.queryParams.parentId = row.id;
            this.type = row.type;
            this.open = true;
            this.title = "维修详情";
            this.getList();
        },
        /** 查询设备维修保养列表 */
        getList() {
            this.loading = true;
            getAction(this.url.list, this.queryParams).then(response => {
                this.dataList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        getTableHeight() {
            this.tableHeight = window.innerHeight - 320
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.id)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.$refs.maintenanceForm.handleAdd(this.info);
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            this.$refs.maintenanceForm.handleUpdate(row);
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            const ids = row.id || this.ids;
            deleteAction(this.url.remove, ids).then(response => {
                this.getList();
                this.$modal.msgSuccess("删除成功");
            }).catch(() => { });
        },
        /** 导出按钮操作 */
        handleExport() {
            this.download(this.url.export, {
                ...this.queryParams
            }, `lnShebeiWeibao_${new Date().getTime()}.xlsx`)
        },
    }
};
</script>
